package net.xju3_4.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.xju3_4.common.utils.JSONUtil;
import net.xju3_4.common.utils.Result;
import net.xju3_4.dao.ShoppingCarDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;

import net.xju3_4.entity.*;
import net.xju3_4.entity.vo.ShoppingCar;

@Controller
public class ShoppingCarController {

    ShoppingCar shoppingCar = new ShoppingCar();

    @RequestMapping("/addOrderItem.do")
    public void addOrderItem(HttpServletRequest request, HttpServletResponse response) {
        String orderId = request.getParameter("orderId");
        String bookId = request.getParameter("bookId");
        String bookTitle = request.getParameter("bookTitle");
        String price = request.getParameter("price");
        String quantity = request.getParameter("quantity");

        ShoppingCar orderItem = new ShoppingCar();
        orderItem.setOrderId(orderId);
        orderItem.setBookId(Integer.parseInt(bookId));
        orderItem.setBookTitle(bookTitle);
        orderItem.setPrice(new java.math.BigDecimal(price));
        orderItem.setQuantity(Integer.parseInt(quantity));

        int success = ShoppingCarDao.addOrderItem(orderItem);
        JSONUtil.printByJSON(response, Result.success(success));
    }

    @RequestMapping("/deleteOrderItem.do")
    public void deleteOrderItem(HttpServletRequest request, HttpServletResponse response) {
        String itemId = request.getParameter("itemId");
        int success = ShoppingCarDao.deleteOrderItem(Integer.parseInt(itemId));
        JSONUtil.printByJSON(response, Result.success(success));
    }


}